package jps.incremental.storage;

import jps.Relativator;
import org.jetbrains.jps.builders.*;
import utils.ExtFileUtil;

import java.io.File;
import java.io.IOException;

/**
 * @author Sergey Serebryakov
 */
public class ChecksumAggregator extends AbstractAggregator {
    ProjectChecksums myChecksums;

    public ChecksumAggregator(Relativator relativator) throws IOException {
        super();
        myChecksums = new ProjectChecksums(myDataStorageRoot, myTargetsState, relativator);
    }

    @Override
    public void handle(File file, BuildTarget<?> target) throws IOException {
        String currentFileChecksum = ExtFileUtil.computeChecksum(file);
        myChecksums.getStorage().saveChecksum(file, target, currentFileChecksum);
    }

    public void close() {
        myChecksums.close();
    }
}
